<template>
  <div class="register-page">
    <van-nav-bar
      title="账号注册"
      left-arrow
      @click-left="$router.push('/login')"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px" color="#fff">
        <van-button
          block
          type="info"
          native-type="submit"
          color="#1cb676"
          font-size="18px"
          >注册</van-button
        >
      </div>
    </van-form>
    <router-link class="link" to="/login">有账号,去登录~</router-link>
  </div>
</template>

<script>
import { register } from "@/api/user";
export default {
  name: "register-page",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    async onSubmit(values) {
      console.log("submit", values);
      const res = await register(values);
      this.$toast.success("注册成功");
      console.log(res);
      this.$router.push("/login");
    },
  },
};
</script>

<style lang="less" scoped>
.van-nav-bar {
  background-color: #1cb676;
}
/deep/.van-nav-bar .van-icon {
  color: #fff;
}
/deep/.van-ellipsis {
  font-size: 18px;
  color: #fff;
}
.van-button {
  font-size: 18px;
}
.link {
  color: #6e6e6e;
  font-size: 12px;
  padding-right: 20px;
  text-align: center;
  display: block;
}
</style>
